package com.cennavi.bigdata.baotou.scripts;

import org.apache.commons.io.FileUtils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;

public class BaotouRTableData {
	
	//comm_rtable
	//rticID、length、cityCode
	public static void main(String[] args) throws Exception {
		List<String> seg_rtable_sql = new ArrayList<String>();
		BufferedReader reader = new BufferedReader(new FileReader("D:\\项目\\包头资料\\更新升级\\2018-10-11\\Segment_Merge_baotou.csv"));
		String line = "";
		while ((line = reader.readLine()) != null) {
			String[] str = line.replace("\"", "").split(",");
			
			String[] rtics = str[7].split(" ");
			String len = String.valueOf(new Double(Double.parseDouble(str[8]) * 1000).intValue());
			for(int i=0;i<rtics.length;i++){
				StringBuffer insertRtable = new StringBuffer();
				String insertRtableSQL = "INSERT INTO comm_rtable(rticID,length,cityCode) VALUES(";
				insertRtable.append(insertRtableSQL);
				//rticID
				insertRtable.append("'").append(rtics[i]).append("',");
				//length
				int length = new Double(Double.parseDouble(len) / rtics.length).intValue();
				insertRtable.append(length).append(",");
				insertRtable.append("150200);");
				seg_rtable_sql.add(insertRtable.toString());
			}
		}
		FileUtils.writeLines(new File("D:\\11pan\\baotou\\baotouNew20181012\\comm_rtable_SQL.sql"), seg_rtable_sql, true);
//		FileUtils.writeLines(new File("D:\\11pan\\baotou\\baotouNew20181012\\comm_rtable_SQL.csv"), seg_rtable_sql, true);
		reader.close();
	}
}
